<?php
namespace app\admin\model;
use think\facade\Log;
use think\Model;
use think\model\concern\SoftDelete;

class Admin extends Model
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;

    protected $type = [
        'last_login_time'  => 'timestamp:Y-m-d H:i:s',
        'birthday'         => 'timestamp:Y-m-d',
    ];

    /**
     * 设置密码MD5
     * @param $value
     * @return string
     */
    public function setPasswordAttr($value)
    {
        return md5($value);
    }

    /**
     * 权限转数组 保存
     * @param $value
     * @return array|string
     */
    public function setRolesAttr($value)
    {
        if(!$value){
            $list = array();
        }else{
            $list = implode(',',array_filter($value));
        }
        return $list;
    }

    /**
     * 权限转数组 读取
     * @param $value
     * @return array|false|string[]
     */
    public function getRolesAttr($value)
    {
        if(!$value){
            $role = array();
        }else{
            $role = explode(',', $value);
        }
        $list = AdminRole::where('id','in',$role)->select();
        return $list;
    }

    /**
     * 获取列表
     */
    static function get_list() {
        return self::where('status','1')->order('sort_order desc,id desc')->select();
    }




}